package com.salton123.processor

import com.salton123.processor.action.IProcessDispatch
import com.salton123.processor.action.ModuleInitializerProcessDispatch
import com.salton123.processor.util.log
import tv.athena.annotation.ModuleInitializer
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.ProcessingEnvironment
import javax.annotation.processing.RoundEnvironment
import javax.lang.model.SourceVersion
import javax.lang.model.element.TypeElement

/**
 * @Time:2021/2/4 10:47
 * @Author:wujinsheng
 * @Description:
 */
class ProcessDispatcher : AbstractProcessor() {

    override fun init(processingEnv: ProcessingEnvironment?) {
        super.init(processingEnv)
        log("init")
    }

    override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?): Boolean {
        log("start process")
        ArrayList<IProcessDispatch>().apply {
            add(ModuleInitializerProcessDispatch())
        }.forEach { it.process(roundEnv, processingEnv) }
        return true
    }

    override fun getSupportedAnnotationTypes(): MutableSet<String> {
        return LinkedHashSet<String>().apply {
            add(ModuleInitializer::class.java.canonicalName)
        }
    }

    override fun getSupportedSourceVersion(): SourceVersion {
        return SourceVersion.RELEASE_7
    }
}
